from aiogram import types
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup

import client_kb
import sqlite_db
from create_bot import dp


class FSM(StatesGroup):
    doc_type_select = State()


async def create_italy(message: types.Message, state: FSMContext):
    user_id = message.from_user.id
    data = await state.get_data()
    await state.finish()
    if "message_to_edit_id" in data:
        await dp.bot.delete_message(
            chat_id=user_id, message_id=data["message_to_edit_id"]
        )
    if "question_message_id" in data:
        await dp.bot.delete_message(
            chat_id=user_id, message_id=data["question_message_id"]
        )

    await sqlite_db.sql_check_user(user_id)
    italy_bill = types.KeyboardButton("BILL 🇮🇹")
    italy_id = types.KeyboardButton("ID 🇮🇹")
    italy_dl = types.KeyboardButton("DL 🇮🇹")
    kb_it = types.ReplyKeyboardMarkup(resize_keyboard=True)
    kb_it.add(italy_id).insert(italy_bill).add(italy_dl).insert(client_kb.back_button)
    await message.answer("Выберите документ для создания", reply_markup=kb_it)
    await FSM.doc_type_select.set()
